package com.zhanghe.study.design_pattern.flyweight_pattern;

import java.util.HashMap;
import java.util.Map;

/**
 * 享元工厂
 * @author zh
 * @date 2022/10/19 11:06
 */
public class FlyweightFactory {

    private Map<String,Flyweight> fsMap = new HashMap<>();

    public Flyweight get(String key){
        Flyweight flyweight = fsMap.get(key);

        // 不存在，创建一个
        if(flyweight == null){
            flyweight = new ConcreteFlyweight(key);
            fsMap.put(key,flyweight);

        }
        return flyweight;
    }
}
